package com.example.allshengmedical.experimentanalyze.activity;


//计算标准差的工具类
public class BiaoZhunCha {

	private float[] array;
	private int num;

	public BiaoZhunCha(float[] array, int num) {
		super();
		this.array = array;
		this.num = num;
	}

	// 获取平均值
	public double getAverage() {
		int sum = 0;
		for (int i = 0; i < num; i++) {
			sum += array[i];
		}
		return (double) (sum / num);
	}

	// 标准差
	public double getStandardDevition() {
		double sum = 0;
		for (int i = 0; i < num; i++) {
			sum += Math.sqrt(((double) array[i] - getAverage())
					* (array[i] - getAverage()));
		}
		if(num ==1){
			return 0;
		}else {
			return (sum / (num - 1));
		}
	
	}

	public float[] getArray() {
		return array;
	}

	public int getNum() {
		return num;
	}

}
